import request from "@Utils/webServerRequest"

/**
 *
 * @param {product_id:商品ID} data
 * @returns
 */
// 商品详情
export const getPreviewDetail = (data) => {
  if (!data.product_id) throw new Error("商品 product_id 不能为空")
  return request({
    url: `api/product/detail`,
    method: "get",
    paramete: {
      // need_conv_pkg: false, // 是否需要转换PKG
      product_id: data.product_id
      // use_std_brand: true
    }
  })
}
// 批量上传素材
export const uploadMaterialApi = (data) => {
  return request({
    url: `api/product/batchUploadImageSync`,
    method: "post",
    data,
    paramete: {}
  })
}

// 发布商品
export const publishProductApi = (data) => {
  // console.log('创建数据+++', data)
  return request({
    url: `api/product/publishProduct`,
    method: "post",
    data,
    paramete: {}
  })
}

// 查询商品类目id的属性列表
export const getCatePropertyV2Api = (category_leaf_id = 0) => {
  return request({
    url: `api/product/getCatePropertyV2`,
    method: "get",
    paramete: {
      category_leaf_id: category_leaf_id || 0
    }
  })
}

// 获取发布规则
export const getProductUpdateRule = (category_id) => {
  return request({
    url: `api/product/getProductUpdateRule`,
    method: "get",
    paramete: {
      category_id
    }
  })
}
// 获取品牌列表
export const getBrandList = (data) => {
  const paramete = {
    category_id: data.category_id,
    query: data.query,
    brand_ids: data.brand_ids
  }
  for (let key in paramete) {
    if (!paramete[key]) {
      delete paramete[key]
    }
  }
  return request({
    url: `api/product/brand/list`,
    method: "get",
    paramete
  })
}
// 编辑商品
export const editProduct = (data) => {
  return request({
    url: `api/product/editV2`,
    method: "post",
    data,
    paramete: {}
  })
}